package com.jagochan.imchat.module.websocket.adaptor;

import com.jagochan.imchat.module.user.domain.entity.User;
import com.jagochan.imchat.module.websocket.domain.enums.WSRespTypeEnum;
import com.jagochan.imchat.module.websocket.domain.vo.resp.WSBaseResp;
import com.jagochan.imchat.module.websocket.domain.vo.resp.resptype.WSLoginSuccess;
import com.jagochan.imchat.module.websocket.domain.vo.resp.resptype.WSLoginUrl;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;

public class WebSocketAdaptor {

    public static WSBaseResp<WSLoginUrl> buildLoginUrlResp(WxMpQrCodeTicket wxMpQrCodeTicket) {
        WSBaseResp<WSLoginUrl> resp = new WSBaseResp<>();
        resp.setType(WSRespTypeEnum.LOGIN_URL.getType());
        resp.setData(new WSLoginUrl(wxMpQrCodeTicket.getUrl()));
        return resp;
    }

    public static WSBaseResp<String> buildWaitAuthorize() {
        WSBaseResp<String> resp = new WSBaseResp<>();
        resp.setType(WSRespTypeEnum.LOGIN_SCAN_SUCCESS.getType());
        resp.setData("扫码成功等待授权");
        return resp;
    }

    public static WSBaseResp<WSLoginSuccess> buildAuthorizeSuccess(User user, String token) {
        WSBaseResp<WSLoginSuccess> resp = new WSBaseResp<>();
        resp.setType(WSRespTypeEnum.LOGIN_SUCCESS.getType());
        WSLoginSuccess wsLoginSuccess = WSLoginSuccess.builder()
                .uid(user.getId())
                .avatar(user.getAvatar())
                .token(token)
                .name(user.getName())
                .power(0).build();

        resp.setData(wsLoginSuccess);
        return resp;
    }

    public static WSBaseResp<String> buildInvalidToken() {
        WSBaseResp<String> resp = new WSBaseResp<>();
        resp.setType(WSRespTypeEnum.INVALIDATE_TOKEN.getType());
        resp.setData("登陆过期");
        return resp;
    }
}
